package com.gitee.zhanyao.codebase.java.weixin.controller;

import com.gitee.zhanyao.codebase.java.weixin.model.WeiXinUserlist;
import com.gitee.zhanyao.codebase.java.weixin.service.IWeiXinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@Slf4j
@RestController
public class WeiXinController {

    @Autowired
    private IWeiXinService iWeiXinService;

    @GetMapping("/sayText")
    public void sayText() {
        String template = "测试 {{xxx}}";
        Map<String, String> templateParams = new HashMap<>();
        templateParams.put("xxx", "填充");
        Set<String> toUsers = new HashSet<>();
        toUsers.add("ZhanYao");
        toUsers.add("one");
        try {
            iWeiXinService.sendMessage(template, templateParams, toUsers);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

    @GetMapping("/getUserlist")
    public void getUserlist() {
        String token = iWeiXinService.getToken();
        try {
            List<WeiXinUserlist> userList = iWeiXinService.getUserList(token, 1, 1);
            log.info(userList.toString());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

}
